<?php
	require_once 'UICell.php';
	//DEBUG
		if(isset($_GET['debug'])) {
			echo '<h1>Debug mode!</h1><br>';
				require_once '../AppController.php';
				$debugUIM = new UIMenu((new AppController())->getApp(10)->menu);
				echo $debugUIM->showMenu();
		}
	//END DEBUG
	
	class UIMenu
	{
		public $menu;
		
		public function __construct($menu) {
				$this->menu = $menu;
		}
		
		//Returns an html-string
		public function showMenu() {
			$cells = $this->menu->getCells();
			
			$result = '<table>';
			
			for($r = 1; $r <= $this->menu->getBiggestRow(); $r++) {
				
				$result = $result.'<tr>';
				
				for($c = 1; $c <= $this->menu->getBiggestColumn(); $c++) {
					$result = $result.'<td>';
					
					//TODO: check for null?
					if(isset($cells[$r][$c]) && !empty($cells[$r][$c])) {
						$cell = $cells[$r][$c]; 
						
						$uicell = new UICell($cell);
						$result = $result.$uicell->showCell();
						
					}
					
					$result = $result.'</td>';
				}
				
				$result = $result.'</tr>';
			}
			
			$result = $result.'</table>';
			
			return $result;
		}
	}
?>